# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=json
_pkgname=nlohmann-json
pkgbase=mingw-w64-${_pkgname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_pkgname}"
pkgver=3.10.5
pkgrel=2
pkgdesc="JSON for Modern C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/nlohmann/json"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
conflicts=("${MINGW_PACKAGE_PREFIX}-nlohmann_json")
provides=("${MINGW_PACKAGE_PREFIX}-nlohmann_json")
replaces=("${MINGW_PACKAGE_PREFIX}-nlohmann_json")
options=('staticlibs' '!strip' '!buildflags')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/nlohmann/json/archive/v${pkgver}.tar.gz"
        "0001-fix-pkgconfig-files.patch")
sha256sums=('5daca6ca216495edf89d167f808d1d03c4a4d929cef7da5e10f135ae1540c7e4'
            '49d5e9e3c860a4c348b1d0a74ad38b6d9b30e73c71cfc64ad6f5c70e40c307d0')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-fix-pkgconfig-files.patch"
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DJSON_BuildTests=ON \
    -DJSON_Install=ON \
    ../${_realname}-${pkgver}

  cmake --build ./
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  ctest ./ || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR=${pkgdir} cmake --install ./
}
